<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<title>view/workArea/tools/incomingTools</title>
		<!-- css代码 start -->
		<link href="../../../css/mui.min.css" rel="stylesheet" />
		<link href="../../../css/global.css" rel="stylesheet" />
		<link href="../../../css/style.css" rel="stylesheet" />
		<link href="../../../css/checkbox.css" rel="stylesheet" />
		<link href="../../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../../css/mui.poppicker.css" rel="stylesheet" />
		<link href="../../../css/task.css" rel="stylesheet" />
		<style>
			.d_int_tp{
				border: 0 !important;
				margin-top: 6px !important;
			}
			.select-tzstate{
				width: 100%;
				border: 0;
				color: #a9a9a9;
				font-size: 16px;
				text-align: left;
				padding: 15px;
			}
			.mui-bar-nav{
				box-shadow: 0 1px 6px #ea1e1a;
			}
			.mui-checkbox input[type=checkbox], .mui-radio input[type=radio]{
				top: 8px;
				right: -10px;
			}
			.details_con .btm{
				height: 50px;
			}
			.item_box .btm li{
				line-height: 30px;
			}
			.item_box .btm li span.i_1{
				background-size: 18px;
			}
			.item_box .btm li span.i_2{
				background-size: 18px;
			}
			.item_box .btm li span {
			    padding-left: 24px;
			}
		</style>
		<!-- css代码 end -->
	</head>
	<body>

		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 id="title" class="mui-title">工具收货</h1>
		</header>
		<div class="mui-content">
			<div class="details_con select_con" id="search">
				<div class="clum">
					<input type="text" class="d_int_tp" id="toolNo" placeholder="请输入工具物料号" />
				</div>
				<div class="clum">
					<input type="text" class="d_int_tp" id="toolNname" placeholder="请输入工具名称" />
				</div>
				<div class="btm autoHeight">
					<p class="selectBtn" id="searchBtn" onclick="selectList()">查 询</p>
				</div>
			</div>
			
			<div class="details_con" style="margin: 30px 0 0 0;">
				<div class="item_box" id="itemBox"></div>
				<div class="btn_box">
					<span class="fl red one" id="submitBtn">批量收货</span>
				</div>
			</div>
		</div>



		<!-- js代码 start -->

		<!-- 基础js start -->
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/utils/h.js"></script>
		<script src="../../../js/constant.js"></script>
		<script src="../../../js/common.js"></script>
		<script src="../../../js/utils/base64.js"></script>
		<script src="../../../js/utils/md5.js"></script>
		<script src="../../../js/utils/sortMap.js"></script>
		<script src="../../../js/utils/http.js"></script>
		<script src="../../../js/app.js"></script>
		<script src="../../../js/mui.picker.js"></script>
		<script src="../../../js/mui.poppicker.js"></script>
		<!-- 基础js end -->

		<script>
			(function($, doc) {
				$.init();

				$.plusReady(function() {
					// 查询可借用工具列表（完好闲置）
					selectList();
					
					// 批量收货
					h("#submitBtn").tap(function() {
						var tools = new Array();
						var toolIds = new Array();
						var ele = document.getElementsByName("checkbox1");
						for (var i = 0; i < ele.length; i++) {
							if(ele[i].checked){
								// 选中的工具信息
								var info = {};
								info["tool_id"] = ele[i].value;
								info["tool_no"] = ele[i].getAttribute("toolNo");
								info["Tool_name"] = ele[i].getAttribute("toolName");
								// 收货所需参数
								tools.push(info);
								toolIds.push(ele[i].getAttribute("toolNo"));
							}
						}
						if (tools.length === 0) {
							app.toast("请选择工具");
						} else {
							receiv(tools, toolIds);
						}
					})
				});
			}(mui, document));
			
			// 查询可借用工具列表(使用post请求)
			function selectList() {
				var toolNo = h("#toolNo").val();
				var toolNname = h("#toolNname").val();
				var enginnerId = app.getUser().enginnerId;

				ajaxPost(BASE_URL + "cc/tool/getToolByFse", {
					"enginnerId": enginnerId,
					"status": "6",
					"toolNo": toolNo,
					"toolNname": toolNname
				}, function(data) {
					if (data.code === 200) {
						var str = '';
						var dataObj = JSON.parse(data.data);
						var list = dataObj.record;
						// 无数据
						if (list.length == 0) {
							h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
							return false;
						}
						// 显示列表
						for (var i = 0; i < list.length; i++) {
							var info = list[i];
							str += '<div class="item">';
							str += '<div class="bar">';
							str += '<span class="number">'+ info.tool_no +'<img src="../../../images/icon_204.png" /></span>';
							str += '<div class="checkbox">';
							str += '<div class="mui-input-row mui-checkbox"> ';
							str += '<input name="checkbox1" value="'+ info.tool_id +'" toolNo="'+ info.tool_no +'" toolName="'+ info.Tool_name +'" type="checkbox" class="rdss"/> ';
							str += '<label></label> ';
							str += '</div> ';
							str += '</div>';
							str += '</div>';
							str += '<div class="text">';
							str += '<span class="l">工具名称：</span> ' + emptyStr(info.Tool_name);
							str += '</div>';
							str += '<div class="type">';
							str += '<p>工具属性：<span>'+ emptyStr(info.tools_type) +'</span><img src="../../../images/icon_221.png"/></p>';
							str += '<p>工具状态：<span>'+ emptyStr(info.tool_status) +'</span><img src="../../../images/icon_205.png"/></p>';
							str += '</div>';
							str += '<ul class="btm" style="overflow:auto">';
							str += '<li><span class="i_1" onclick="showLogistics(\''+ info.ExpressNumber +'\', \''+ info.shipercode +'\', \''+ info.enginner_mobile +'\')">查看物流</span></li>';
							str += '<li><span class="i_2" onclick="receivToolInfo(\''+ info.tool_id +'\',\''+ info.tool_no +'\',\''+ info.Tool_name +'\')">确认收货</span></li>';
							str += '</ul>';
							str += '</div>';
						}
						h('#itemBox').html(str);
					} else {
						h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
						app.toast(data.msg)
					}
				}, function(errorMsg) {
					h("#itemBox").html('<div class="nodata">—— 暂无数据 ——</div>');
					app.toast("数据获取失败，请检查网络连接");
				});
			}
			
			// 单个收货参数内容
			function receivToolInfo(id, no, name) {
				var tools = new Array();
				var info = {};
				info["tool_id"] = id;
				info["tool_no"] = no;
				info["Tool_name"] = name;
				// 收货所需参数
				tools.push(info);
				receiv(tools);
			}
			
			// 确认收货
			function receiv(tools, toolIds) {
				var btnArray = ["取消", "确认"];
				mui.confirm('是否确认收货'+ emptyStr(toolIds) +'？', '工具收货', btnArray, function(e) {
					if (e.index == 0) {
						setTimeout(function() {
							$.swipeoutClose(elem);
						}, 0);
					} else {
						// POST参数对象
						var postParam = {
							"enginnerId" : app.getUser().enginnerId,
							"toolInfo" : JSON.stringify(tools)
						}
						// 收货接口调用
						app.showWaiting('加载中...')
						ajaxPost(BASE_URL + "cc/tool/toolReceiving", postParam, function(data) {
							app.closeWaiting()
							// console.log(JSON.stringify(data));
							if (data.code == 200) {//查询成功
								app.toast("保存成功");
								selectList()
							} else {//查询失败
								app.toast("保存失败");
							}
						}, function(errorMsg) {
							app.closeWaiting()
							console.log(JSON.stringify(errorMsg))
						});
					}
				});
			}
			
			// 查看物流
			function showLogistics(logisticNo, shipercode, custname) {
				// test
				app.jumpTo("../logistics/logistics.html", "view/workArea/logistics/logistics", {
					"logisticNo" : logisticNo,
					"shipercode" : shipercode,
					"custname" : custname
				})
			}
			
		</script>
		<!-- js代码 end -->
	</body>
</html>
